package com.pes.arcww.dao;

import java.util.Collection;
import com.pes.arcww.form.Items;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository
public class ItemsDAOImpl implements ItemsDAO{
	
	@Autowired
	private SessionFactory sessionFactory;
	
	public void addItem(Items item) {
		sessionFactory.getCurrentSession().save(item);
	}

	@SuppressWarnings("unchecked")
	public Collection<Items> listItems() {
		return sessionFactory.getCurrentSession().createQuery("from Items").list();
	}

	public void removeItem(Integer id) {
		Items item = (Items) sessionFactory.getCurrentSession().load(Items.class, id);
		if(null != item){
			sessionFactory.getCurrentSession().delete(item);
		}
	}

	public void updateItem(Items item) {
		sessionFactory.getCurrentSession().update(item);
	}

}
